<?php
	class database
	{
		//Khai bao thuoc tinh
		var $sql="";
		var $connection="";
		var $cursor=null;	// chua kq mysql_query
		
		//Khai bao phuong thuc
		function database()
		{
			include('db.inc');
			$this->connection =@mysql_connect($hostname,$dbuser,$dbpass);
			if(!$this->connection)
				die("Trang web đang bảo trì, vui lòng quay lại sau(1.1)");
				
			
			if($dbname=="" || !mysql_select_db($dbname,$this->connection))
				die("Trang web đang bảo trì, vui lòng quay lại sau(1.2)");
		}		
		
		
		function SetQuery($sql)	//Gán cau lenh sql cho thuoc tinh $sql
		{
			$this->sql=$sql;
		}
		
		function Query()	//Gán dl cho thuoc tinh $cursor
		{
			mysql_query("set names utf8");
			$this->cursor = mysql_query($this->sql,$this->connection);
			return $this->cursor;
		}
		
		function LoadAllRow()
		{
			if(!($cur=$this->Query()))
			{
				return null;
			}
			$array=array();
			while($row=mysql_fetch_assoc($cur))
			{
				$array[]=$row;
			}
			mysql_free_result($cur);
			return $array;
		}
		function LoadOneRow()
		{
			if(!($cur=$this->query()))
			{
				return null;
			}
			$row=mysql_fetch_assoc($cur);
			mysql_free_result($cur);
			return $row;
		}
		function disconnect()
		{
			mysql_close($this->connection);
		}
		//function orders====================================
		function save_user($id_customer,$prenom,$nom,$organisation,$titre,$courriel,$adresse,$ville,$postal,$pays,$province,$phone,$Cellulaire,$different_delivery)
		{
			$sql="insert into customer(id_customer,prenom,nom,organisation,titre,courriel,adresse,ville,postal,pays,province,phone,Cellulaire,different_delivery) values('$id_customer','$prenom','$nom','$organisation','$titre','$courriel','$adresse','$ville','$postal','$pays','$province','$phone','$Cellulaire','$different_delivery')";
			$this->SetQuery($sql);
			$this->Query();
		}
		function save_orders($serial,$id_order,$id_customer,$total,$livraison,$tps,$tvq,$date,$type,$bank_transaction_id)
		{
			$sql="insert into orders(serial,id_order,id_customer,total,livraison,tps,tvq,date,type,bank_transaction_id) values('','$id_order','$id_customer','$total','$livraison','$tps','$tvq','$date','$type','$bank_transaction_id')";
			$this->SetQuery($sql);
			$this->Query();
		}
		function save_order_detail($serial_order,$product,$name,$qty,$price,$type_don,$frequence,$debutant)
		{
			
			$sql="insert into order_detail(serial_order,product,name,qty,price,type_don,frequence,debutant) values('$serial_order','$product','$name','$qty','$price','$type_don','$frequence','$debutant')";
			$this->SetQuery($sql);	
			$this->Query();
		}
	}
?>